import 'package:flutter/material.dart';
//import 'package:transparent_image/transparent_image.dart';
import '../../routers/application.dart';


class FactoryOverview extends StatefulWidget {
  @override
  FactoryOverviewState createState() => new FactoryOverviewState();
}

class FactoryOverviewState extends State<FactoryOverview> {
  List<Map<String, Object>> _indexCardDataList = new List();
  List<Map<String, Object>> _opCardDataList = new List();
  @override
  void initState() {
    super.initState();
    _indexCardDataList.add({"num": 123, "text": "累计积分"});
    _indexCardDataList.add({"num": 3, "text": "平台星级"});
    _indexCardDataList.add({"num": 42, "text": "客户个数"});
    _indexCardDataList.add({"num": 85, "text": "数字化指数"});
    _indexCardDataList.add({"num": 85, "text": "累计订单"});
    _indexCardDataList.add({"num": 20, "text": "在产订单"});
    _indexCardDataList.add({"num": 132, "text": "上线设备"});
    _indexCardDataList.add({"num": 3, "text": "融资总量"});

    _opCardDataList.add({
      "icon": Icon(Icons.inbox),
      "title": "订单获取能力位于30%, 偏低",
      "subtitle": "提升订单获取能力, 生意自动找上门",
      "action": "马上提升",
      "route":  "/factory/gain_order_capability"
    });
    _opCardDataList.add({
      "icon": Icon(Icons.inbox),
      "title": "预分配订单 100 个",
      "subtitle": "WDXC-001型弯管",
      "action": "马上确认",
      "route":  "/manufacture/check_split"
    });
    _opCardDataList.add({
      "icon": Icon(Icons.schedule),
      "title": "生产中订单 200 个",
      "subtitle": "进度正常/延期",
      "action": "查看详情",
      "route":  "/factory/orders_overview"
    });
    _opCardDataList.add({
      "icon": Icon(Icons.monetization_on),
      "title": "融资租赁 5 单",
      "subtitle": "快捷灵活低成本，按需租赁高效率",
      "action": "马上申请",
      "route":  "/factory/biz_list/1"
    });
    _opCardDataList.add({
      "icon": Icon(Icons.shopping_cart),
      "title": "采购零配件189单，为您节省11万元",
      "subtitle": "盘活设备资产，激活生产活力",
      "action": "清点盘活",
      "route":  "/manufacture/check_progress"
    });
    _opCardDataList.add({
      "icon": Icon(Icons.build),
      "title": "到厂维修3次，节省工效48小时",
      "subtitle": "专业设备维修工程师，随叫随到",
      "action": "现在就要",
      "route":  "/manufacture/check_progress"
    });
    _opCardDataList.add({
      "icon": Icon(Icons.ac_unit),
      "title": "设备转入 1单， 转出 2单",
      "subtitle": "盘活设备资产，激活生产活力",
      "action": "清点盘活",
      "route":  "/manufacture/check_progress"
    });
  }

  @override
  Widget build(BuildContext context) {
    //super.build(context);
    return CustomScrollView(
      shrinkWrap: true,
      slivers: <Widget>[
        SliverAppBar(
        /*  leading: FadeInImage.assetNetwork(
            placeholder: "assets/images/house.png",
            image: 'https://picsum.photos/250?image=9',
          ),
*/
          flexibleSpace: FlexibleSpaceBar(
              //可以展开区域，通常是一个FlexibleSpaceBar
              centerTitle: true,
              title: Text("揭阳加成塑胶花厂"),
              background: Image.network(
                "https://iiot.jp/wp-content/uploads/2019/01/dc4775226e5370fa43eeef2d0b421186.jpg",
                fit: BoxFit.cover,
              )),
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.shopping_cart),
              tooltip: 'Open shopping cart',
              onPressed: () {
                Application.router.navigateTo(context, "/placeorder");
              },
            ),
          ],
          primary: true, //是否预留高度
          forceElevated: true,
          automaticallyImplyLeading: true,
          snap: false, //与floating结合使用
          expandedHeight: 100.0, //展开高度
          floating: false, //是否随着滑动隐藏标题
          pinned: true, //是否固定在顶部
          backgroundColor: Colors.lightGreen,
        ),
        /*SliverPadding(
          padding: const EdgeInsets.all(20.0),
          sliver: SliverList(
            delegate: SliverChildListDelegate(
              <Widget>[
                const Text('I\'m dedicating every dddday to you!!!!'),
                const Text('Domestic life was never quite my style'),
                const Text('When you smile, you knock me out, I fall apart'),
                const Text('And I thought I was so smart'),
              ],
            ),
          ),
        ),*/
        SliverPadding(
          padding: const EdgeInsets.all(0.0),
          sliver: SliverList(
            delegate: SliverChildBuilderDelegate(
              (BuildContext context, int index) {
                return ListTile(
                  leading: _opCardDataList[index]["icon"],
                  title: Text(_opCardDataList[index]["title"]),
                  subtitle: Text(_opCardDataList[index]["subtitle"]),
                  trailing: FlatButton(
                    child: Text(_opCardDataList[index]["action"]),
                    onPressed: () {
                      Application.router.navigateTo(context, _opCardDataList[index]["route"]);
                    },
                  ),
                );
              },
              childCount: _opCardDataList.length,
            ),
          ),
        ),
        SliverGrid(
          gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
            maxCrossAxisExtent: 200.0,
            mainAxisSpacing: 10.0,
            crossAxisSpacing: 10.0,
            childAspectRatio: 4.0,
          ),
          delegate: SliverChildBuilderDelegate(
            (BuildContext context, int index) {
              return Container(
                  alignment: Alignment.center,
                  //color: Colors.teal[100 * (index % 9)],
                  color: Colors.blue.withAlpha(30),
                  child: Column(children: <Widget>[
                    Text(_indexCardDataList[index]["num"].toString(),
                        style: new TextStyle(
                          color: Color.fromARGB(255, 50, 50, 50),
                          fontSize: 22.0,
                        )),
                    Text(_indexCardDataList[index]["text"])
                  ]));
            },
            childCount: _indexCardDataList.length,
          ),
        ),


        SliverToBoxAdapter(
          child: Container(
            width: 100,
            height: 300,
          )
        ),


      ],
    );
  }

  void testPress(BuildContext context, int index) {
    final snackBar = SnackBar(
      content: Text('Yay! A SnackBar! $index'),
      action: SnackBarAction(
        label: 'Undo',
        onPressed: () {
          // Some code to undo the change.
        },
      ),
    );

    // Find the Scaffold in the widget tree and use
    // it to show a SnackBar.
    Scaffold.of(context).showSnackBar(snackBar);
  }
}
